package cn.jiangxiong.pethome.system.user.service.impl;

import cn.jiangxiong.pethome.constants.BaseConstants;
import cn.jiangxiong.pethome.system.login.domian.PhoneRegister;
import cn.jiangxiong.pethome.system.user.domain.User;
import cn.jiangxiong.pethome.system.user.mapper.UserMapper;
import cn.jiangxiong.pethome.system.user.service.IUserService;
import cn.jiangxiong.pethome.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByPhone(String phone) {
        return userMapper.findByPhone(phone);
    }

    @Override
    public void add(PhoneRegister register) {
        User user = new User();
        user.setPassword(register.getPassword());
        user.setCreatetime(new Date());
        user.setUsername(register.getPhone());
        user.setPhone(register.getPhone());
        user.setState(BaseConstants.User.STATE_NORMAL);
        userMapper.add(user);
    }
}